#include "include/stack.h"

//初始化栈
void init_stack(stack_int_t*stack){
    stack->top = -1;
    memset(stack->add_arr,0,sizeof(stack->add_arr));
    return;
}
//入栈
void push_stack(stack_int_t *stack,int data){
    if(stack->top == ADDRESS_ARR_SIZE-1){
        printf("stack is full\n");
        return;
    }
    stack->top++;
    stack->add_arr[stack->top] = data;
    return;
}
//出战
int pop_stack(stack_int_t *stack){
    if(stack->top == -1){
        printf("stack is empty\n");
        return -10;
    }
    int temp = stack->top;
    stack->top--;
    return stack->add_arr[temp];
}
//读取栈顶元素但不出栈
int read_top(stack_int_t *stack){
    if(stack->top == -1){
        printf("stack is empty\n");
        return -10;
    }
    return stack->add_arr[stack->top];
}
//清空栈
void clear_stack(stack_int_t *stack){
    stack->top = -1;
    memset(stack->add_arr,0,sizeof(stack->add_arr));
    return;
}